﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package ZLocalization {
    import Engine.Interfaces.*;
    import ZLocalization.Substituters.*;

    public class Localizer implements ILocalizer {

        protected static var substituterMap:Object = {
            es:SubstituterEs,
            en_UD:SubstituterEnFlip,
            en_PI:SubstituterEnZy,
            it:SubstituterIt,
            pt:SubstituterPt,
            fr:SubstituterFr,
            de:SubstituterDe
        };

        public const MASC:String = "masc";
        public const FEM:String = "fem";
        private const IMAGE_PACKAGE:String = "LocalizedImages";
        protected const LOCALE_DELIMITER:String = "_";
        private const NO_COUNT:int = -1;
        private const DEFAULT_GENDER:String = "masc";

        protected var m_substituter:SubstituterSimple;
        protected var m_raw:Object;
        protected var m_cached:Object;
        protected var m_locale:String;
        var m_fontMapper:IFontMapper;

        public function Localizer(_arg1:Object){
        }
        protected function setSubstituter():void{
            if (substituterMap.hasOwnProperty(this.m_locale)){
                this.m_substituter = new (substituterMap[this.m_locale])();
            } else {
                if (substituterMap.hasOwnProperty(this.langCode)){
                    this.m_substituter = new (substituterMap[this.langCode])();
                } else {
                    this.m_substituter = new SubstituterSimple();
                };
            };
        }
        public function get langCode():String{
            return (this.m_locale.split(this.LOCALE_DELIMITER)[0]);
        }
        public function get localeCode():String{
            return (this.m_locale);
        }
        public function setAsGlobalInstance():void{
            ZLoc.instance = this;
        }
        public function t(_arg1:String, _arg2:String, _arg3:Object=null):String{
            return (this.translate(_arg1, _arg2, _arg3));
        }
        public function tk(_arg1:String, _arg2:String, _arg3:String="", _arg4:int=-1):LocalizationObjectToken{
            return (this.createToken(_arg1, _arg2, _arg3, _arg4));
        }
        public function tn(_arg1:String, _arg2:String="masc"):LocalizationName{
            return (this.createName(_arg1, _arg2));
        }
        public function createToken(_arg1:String, _arg2:String, _arg3:String="", _arg4:int=-1):LocalizationObjectToken{
            return (new LocalizationObjectToken(this.getString(_arg1, _arg2), _arg3, _arg4));
        }
        public function createName(_arg1:String, _arg2:String="masc"):LocalizationName{
            return (new LocalizationName(_arg1, _arg2));
        }
        public function translate(_arg1:String, _arg2:String, _arg3:Object=null):String{
            var _local4:LocalizedString = this.getString(_arg1, _arg2);
            if (_local4 == null){
                return ((((("Cannot find string " + _arg2) + " in package ") + _arg1) + "."));
            };
            return (_local4.toString(((_arg3) || ({})), this.m_substituter));
        }
        public function translateImagePath(_arg1:String):String{
            var _local2:LocalizedString = this.getString(this.IMAGE_PACKAGE, _arg1);
            if (_local2 == null){
                return (("Cannot find path " + _arg1));
            };
            return (_local2.getVariation(LocalizedString.ORIGINAL));
        }
        public function getString(_arg1:String, _arg2:String):LocalizedString{
            return (null);
        }
        public function getFontMapper():IFontMapper{
            return (this.m_fontMapper);
        }

    }
}//package ZLocalization 
